// 1.引入公用样式表
require("../../assets/css/index.less");

// 2.引入当前样式表
require("./back.less");

require("animate.css");
let dom = require("../../utils/dom.js");
let vali = require("../../utils/validator.js");
let https = require("../../utils/https.js");
import CaptchaMini from "captcha-mini";
console.log(CaptchaMini);
// let cap = require("captcha-mini");
https.get("api/shared/province", function (res) {
  console.log(res);
});
let captchaCode = ""; // 当前验证码

// 创建验证码渲染器
const captchaDrawer = new CaptchaMini();

captchaDrawer.draw(document.querySelector("#captcha"), function (code) {
  captchaCode = code;
});

dom.$(".for-inp").addEventListener("submit", function (e) {
  e.preventDefault();
  let account = dom.$("#user").value; //用户名
  let vcoude = dom.$("#code").value; //验证码
  let password = dom.$("#pass").value; //密码
  let isPas = dom.$("#checkpas").value; // 确认密码
  console.log(account, vcoude, password, isPas);
  if (!vali.cheUser(account) || account == null) {
    alert("账户格式不对，且不能为空");
    return;
  } else if (
    vcoude.toLowerCase() !== captchaCode.toLowerCase() ||
    vcoude == null
  ) {
    alert("验证码错误，且不能为空");
    return;
  } else if (!vali.chePas(password) || password == null) {
    alert("密码格式错误，大于5小于17的长度,且不能为空");
    return;
  } else if (password !== isPas || isPas == null) {
    alert("前后密码不一致，请确认后提交，且不能为空");
  } else {
    dom.$("#user").addEventListener("bulr", function () {
      https.post("api/user/isExist", { account }, function (res) {
        if (res.errno == 10002) {
          alert("账号用户名（电话）已存在");
        }
      });
    });
  }
});
